<?php
/**
 * a cumulus page container serves as a container for cumulus page block objects
 * a container generally represents a section of a page
 *
 */
class Cms_Page_Container
{
    /**
     * this is an array of Cms_Page_Block objects
     *
     * @var array
     */
    protected $_blocks = array();
    /**
     * adds a new block	
     *
     * @param string $key
     * @return Cms_Page_Block
     */
    public function addBlock ($key)
    {
        $block = new Cms_Page_Block();
        $this->_blocks[$key] = $block;
        return $block;
    }
    /**
     * return a block if it exists
     *
     * @param string $key
     * @return Cms_Page_Block
     */
    public function getBlock ($key)
    {
        if ($this->hasBlock($key)) {
            return $this->_blocks[$key];
        }
        return false;
    }
    /**
     * returns all of the container's blocks
     *
     * @return array
     */
    public function getBlocks ()
    {
        if (count($this->_blocks) > 0) {
            return $this->_blocks;
        }
        return false;
    }
    /**
     * renders each of the container's blocks 
     *
     * @return XHTML
     */
    public function render ()
    {
        $xhtml = null;
        if (count($this->_blocks) > 0) {
            foreach ($this->_blocks as $block) {
                $xhtml .= $block->render();
            }
        }
        return $xhtml;
    }
    /**
     * test to see if the container contains a specific block
     *
     * @param string $key
     * @return bool
     */
    public function hasBlock ($key)
    {
        return array_key_exists($key, $this->_blocks);
    }
}
?>